package com.yungu.swift.assets.driver.dao;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.assets.driver.model.dto.DriverDto;
import com.yungu.swift.assets.driver.model.dto.MonitorStatDto;
import com.yungu.swift.assets.driver.model.param.AdminDriverMonitorParam;
import com.yungu.swift.assets.driver.model.vo.*;
import com.yungu.swift.base.mapper.IMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 司机业务Mapper
 *
 * @author cuixiuyin - Generate
 * @version 1.1.1-SNAPSHOT
 * @since 2018-07-05 16:23
 */
public interface DriverMapper extends IMapper<DriverDto> {


    /**
     * 后台获取列表
     *
     * @param params     Map
     * @param pageBounds PageBounds
     * @return PageList<AdminDriverVo>
     */
    PageList<AdminDriverVo> queryPageAdmin(Map<String, Object> params, PageBounds pageBounds);

    /**
     * 导出数据
     *
     * @param map
     * @return
     */
    List<DriverExportVo> exportAdmin(Map<String, Object> map);

    /**
     * 根据token获取司机信息
     *
     * @param map Map
     * @return DriverVo
     */
    DriverVo selInfoByTokenOrId(Map<String, Object> map);

    /**
     * 根据车牌号查询该车牌号下已工作的司机
     *
     * @param map Map
     * @return List<DriverDto>
     */
    List<DriverDto> findWorkedDriverByCarNo(Map<String, Object> map);

    /**
     * 获取司机和扩展信息
     *
     * @param paramsMap Map
     * @return List<DriverDto>
     */
    List<DriverDto> listExtend(Map<String, Object> paramsMap);

    /**
     * 修改司机状态
     *
     * @param driverDto DriverDto
     * @return int
     */
    int changeAccount(DriverDto driverDto);


    /**
     * 后台-获取app/区域代理/公司下的司机总数
     *
     * @param params
     * @return
     */
    int getCountAdmin(Map<String, Object> params);

    /**
     * 后台-获取app/区域代理/公司下的订单总数
     *
     * @param params Map
     * @return int
     */
    int getOrderCount(Map<String, Object> params);

    /**
     * 获取司机的uuid列表
     *
     * @param params Map
     * @return List<String>
     */
    List<String> getDriverUuidList(Map<String, Object> params);


    /**
     * 获取同应用的同城司机
     *
     * @param params
     * @return
     */
    List<String> getTheSameCityDriver(Map<String, Object> params);

    /**
     * 获取司机
     *
     * @param uuid String
     * @return DriverDto
     */
    DriverDto get(String uuid);

    /**
     * 获得可抢单司机
     *
     * @param doingMap Map
     * @return List<String>
     */
    List<String> filterGrabDriver(Map<String, Object> doingMap);

    /**
     * getDriverByCarTypeIdReservation
     *
     * @param doingMap Map
     * @return List<String>
     */
    List<String> filterGrabDriverReservation(Map<String, Object> doingMap);

    /**
     * filterWorkUuid
     *
     * @param doingMap Map
     * @return List<String>
     */
    List<String> filterWorkUuid(Map<String, Object> doingMap);

    /**
     * 获取报警信息
     *
     * @param map Map
     * @return List<DriverMonitorVo>
     */
    List<DriverMonitorVo> getWindowDetailAlarm(Map<String, Object> map);

    /**
     * getDriver
     *
     * @param uuid String
     * @return DriverDto
     */
    DriverDto getDriver(String uuid);

    /**
     * 批量添加
     *
     * @param driverDtoList List<DriverDto>
     * @return int
     */
    int addBatch(List<DriverDto> driverDtoList);

    /**
     * 监控地图查询今日司机接口
     *
     * @param driverMonitorParam Map
     * @return List<MonitorDriverListVo>
     */
    List<MonitorDriverListVo> listTodayDriverMonitor(AdminDriverMonitorParam driverMonitorParam);

    /**
     * 监控地图查询今日司机接口
     *
     * @param driverMonitorParam Map
     * @return Map<String, Integer>
     */
    List<MonitorStatDto> statOnlineDriversToday(AdminDriverMonitorParam driverMonitorParam);

    /**
     * 监控地图查询今日司机接口 —— 分页数据
     *
     * @param driverMonitorParam Map
     * @return List<MonitorDriverListVo>
     */
    PageList<MonitorDriverListVo> listTodayDriverMonitor(AdminDriverMonitorParam driverMonitorParam, PageBounds pageBounds);

    /**
     * 监控地图司机简要弹窗状态
     *
     * @param params Map
     * @return List<MonitorDriverDetailVo>
     */
    List<AdminMonitorDriverDetailVo> getMonitorDriverDetail(Map<String, Object> params);

    /**
     * 今日司机跨城订单信息
     *
     * @param params Map
     * @return List<MonitorDriverDetailVo>
     */
    AdminMonitorDriverDetailVo getDriverTodayCrosstownInfo(Map<String, Object> params);


    /**
     * 修改司机状态
     *
     * @param driverDto DriverDto
     * @return int
     */
    int driverDimission(DriverDto driverDto);

    /**
     * 批量更新
     *
     * @param driverDtoList List<DriverDto>
     * @return int
     */
    int updateBatch(List<DriverDto> driverDtoList);

    /**
     * 检索有效司机（未离职）
     *
     * @param params Map
     * @return List<DriverDto>
     */
    List<DriverDto> getValidDriver(Map params);


    /**
     * 获取可派单司机（只取前一百个）
     *
     * @param params 过滤参数
     * @return AjaxList
     * @author Zerrion
     * @date 2018/1/3
     */
    List<String> filterAssignDriver(Map<String, Object> params);


    /**
     * 根据电话或者身份证查询司机
     *
     * @param mobile String
     * @param idCard String
     * @return List<DriverDto>
     */
    List<DriverDto> findDriverByMobileOrId(@Param("mobile") String mobile, @Param("idCard") String idCard);


    @Update("update t_driver set order_count=(order_count+1) where uuid=#{uuid}")
    void incrDriOrderCountByUuid(@Param("uuid") String uuid);

    PageList<JoinAssignDriverVo> queryByAssign(Map<String, Object> params, PageBounds pageBounds);

    /**
     * 查询排队中司机
     *
     * @param params
     * @return
     */
    PageList<QueueDriverVo> queryQueueDriver(Map<String, Object> params);

    /**
     * 查询空闲司机
     *
     * @param params
     * @return
     */
    PageList<JoinAssignDriverVo> queryFreeDriver(Map<String, Object> params, PageBounds pageBounds);

    /**
     * 获取开启顺路模式司机
     */
    List<DriverSameWayInfoVo> getSameWayDriverUuid(@Param("businessType") Integer businessType, @Param("list") List<String> list);

    /**
     * 查询司机今天是否有已完成订单
     */
    @Select("<script>select count(0) from t_order o inner join t_order_fare f on f.order_uuid = o.uuid where o.actual_driver_uuid=#{driverUuid} " +
            "and o.main_status in (3,4) and DATE(f.confirm_time) = DATE(NOW()) <if test='sameWayModel !=null'> and same_way_order = 1</if></script>")
    int queryDriverTodayOrder(@Param("driverUuid") String driverUuid, @Param("sameWayModel") Integer sameWayModel);

    /**
     * 关闭司机顺路模式
     *
     * @param businessType
     * @return
     */
    @Update("update t_driver set same_way_model = 0 where FIND_IN_SET(business_type,#{businessType}) and same_way_model = 1")
    int closeDriverSameWayModel(@Param("businessType") String businessType);

    /**
     * 关闭司机顺路模式
     *
     * @param driverUuid
     * @return
     */
    @Select("select business_type,remind_type,listen_down,appoint_time_start,appoint_time_end," +
            "same_way_model,reject_station_order,same_way_address,same_way_lng,same_way_lat" +
            " from t_driver where uuid = #{driverUuid}")
    DriverRemindTypeVo getDriverRemindType(@Param("driverUuid") String driverUuid);

    /**
     * 获取司机开通城市或者区域
     *
     * @param driverUuid
     * @return
     */
    List<DriverManageInfoVo> getManageInfo(@Param("driverUuid") String driverUuid);

    /**
     * 关闭不接火车站订单
     *
     * @param businessType
     * @return
     */
    @Update("update t_driver set reject_station_order = 0 where FIND_IN_SET(business_type,#{businessType}) and reject_station_order = 1")
    int closeDriverStationModel(@Param("businessType") String businessType);

    /**
     * 司机解绑车辆
     *
     * @param uuid
     * @return
     */
    @Update("update t_driver set token = null,car_uuid = null where uuid = #{uuid}")
    int unBindCar(@Param("uuid") String uuid);

    /**
     * 查询司机扫码信息
     *
     * @param driverUuid
     * @return
     */
    ScanCodeDriverInfoVo getScanCodeDriverInfo(@Param("driverUuid") String driverUuid);
}